﻿using EMoney.IStock.Client.Models.Cpyx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EMoney.IStock.Client.DataAccess.Cpyx
{
    /// <summary>
    /// 收益≥10%的局数数据访问类
    /// </summary>
    public class KGameCountDal
    {
        /// <summary>
        /// 新增收益≥10%的局数
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int AddKGameCount(KGameCount obj)
        {
            string sql = "insert into K_GameCount(UserID,GameDate,GameCount,UpdateTime) values(@UserID,@GameDate,@GameCount,getdate())";

            SQLTools tools = new SQLTools();

            tools.AddSqlParameter("UserID", System.Data.SqlDbType.Int, obj.UserID);
            tools.AddSqlParameter("GameDate", System.Data.SqlDbType.DateTime, obj.GameDate);
            tools.AddSqlParameter("GameCount", System.Data.SqlDbType.Int, obj.GameCount);

            return SQLHelper.ExecuteNonQuery(ConnectionManager.Emfstock, System.Data.CommandType.Text, sql, tools.GetSqlParameters());
        }

        /// <summary>
        /// 修改收益≥10%的局数
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int UpdateKGameCount(KGameCount obj)
        {
            string sql = "update K_GameCount set GameCount=@GameCount,UpdateTime=getdate() where UserID=@UserID and GameDate=@GameDate";

            SQLTools tools = new SQLTools();

            tools.AddSqlParameter("UserID", System.Data.SqlDbType.Int, obj.UserID);
            tools.AddSqlParameter("GameDate", System.Data.SqlDbType.DateTime, obj.GameDate);
            tools.AddSqlParameter("GameCount", System.Data.SqlDbType.Int, obj.GameCount);

            return SQLHelper.ExecuteNonQuery(ConnectionManager.Emfstock, System.Data.CommandType.Text, sql, tools.GetSqlParameters());
        }

        /// <summary>
        /// 获取收益≥10%的局数
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="gameDate"></param>
        /// <returns></returns>
        public KGameCount GetKGameCount(int userid, DateTime gameDate)
        {
            string sql = "select * from K_GameCount where UserID=@UserID and GameDate=@GameDate";

            SQLTools tools = new SQLTools();

            tools.AddSqlParameter("UserID", System.Data.SqlDbType.Int, userid);
            tools.AddSqlParameter("GameDate", System.Data.SqlDbType.DateTime, gameDate);

            return SQLHelper.GetDataByColumns<KGameCount>(ConnectionManager.Emfstock, sql, tools.GetSqlParameters());
        }
    }
}
